﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TranslateRotate : MonoBehaviour
{
    public GameObject Bulletsprefab;//子弹预制体
    public float speed = 5f;
    public float rotateSpeed = 90;
    private Transform firePoint;//开火点

    private void Start()
    {
        firePoint = transform.Find("firePoint");
    }

    private void Update()
    {
        if (Input.GetKey(KeyCode.W))
        {
            transform.Translate(Vector3.right * Time.deltaTime * -speed);
        }
        if (Input.GetKey(KeyCode.S))
        {
            transform.Translate(Vector3.right * Time.deltaTime * speed);
        }
        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(Vector3.up * Time.deltaTime * rotateSpeed);
        }
        if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(Vector3.up * Time.deltaTime * -rotateSpeed);
        }
        if (Input.GetKey(KeyCode.Space))
        {
            Instantiate(Bulletsprefab, firePoint.position, firePoint.rotation);
        }
    }
}